<%@page import="content.CategoryContent"%>
<%@page import="transfer.UserRole"%>
<%@page import="java.util.ArrayList"%>
<%@page import="transfer.User"%>
<%@page import="controller.SessionAttribute"%>
<div id="header">
    <div id="logo"><a href="index.jsp"><img src="images/logo.gif"></a></div>
    <a href="index.jsp?content=cart" style="color: #555555;">
        <div id="cart">
            <h3>Shipping cart</h3>
            <% 
                session = request.getSession();
                transfer.Order order = (transfer.Order) session.getAttribute(SessionAttribute.CART);
            %>
            Products: <h id="goodsCount"><% if (order != null) {
                out.print(order.getCommodities().size()); 
            } else {
                out.print(0); 
            } 
            %></h> <h id="totalCostHeader">(<% if (order != null) {
                out.print(order.getCostCommodities());
            } else {
                out.print(0);
            }
            %> $)</h>
        </div>
    </a>
    <div id="welcome">
        <div id="user_line">
            <%
                session = request.getSession();
                User user = null;
                Boolean signin = (Boolean) session.getAttribute(SessionAttribute.SIGN_IN);
                if (signin != null && signin.booleanValue()) {
                    user = (User) session.getAttribute(SessionAttribute.USER);
                    %>
                        Hello, <a href="index.jsp?content=dashboard">
                            <%
                                  out.println(user.getFirstName().toString()
                                          + " " 
                                          + user.getLastName().toString());
                            %>
                        </a>
                        <a id="logout" onclick="logout()">Sign Out</a>
                        <script type="text/javascript" src="js/logout.js"></script>
                    <%
                } else {
                    %>
                    <a href="index.jsp?content=signin">Sign in</a> or <a href="index.jsp?content=registration">registration</a>
                    <%
                }
            %>
        </div>
        <%
                if (signin != null && signin.booleanValue()) {
                    ArrayList roles = user.getRoles();
                    if (roles.contains(UserRole.WAREHOUSE_EMPLOYEE)
                            || roles.contains(UserRole.ADMIN)
                            || roles.contains(UserRole.COURIER)) {
        %>
        <div id="roles">
            <a href="admin/admin.jsp">Go to administration panel</a>            
        </div>
        <%
                    }
                }
        %>
    </div>
    <div id="links">
        <a href="index.jsp">Main</a>
        <%
                if (signin == null || !signin.booleanValue()) {
        %>
        <a href="index.jsp?content=condition">Verify the order</a>
        <%
                } else {
        %>
        <a href="index.jsp?content=dashboard">Dashboard</a>
        <%
                }
        %>
        <a href="index.jsp?content=contacts">Contacts</a>
    </div>
</div>
<div id="menu">
    <%  
                ArrayList categories = CategoryContent.getCategories(10);
                if (categories != null)
                for (int i = 0; i < categories.size(); i++) {
                
    %>
    <div class="menu-item"><a href="index.jsp?content=category&type=<%= i+1 %>"><img src="images/<%= ((transfer.CommodityCategory) categories.get(i)).getImageCategory() %>"><br><%= ((transfer.CommodityCategory)categories.get(i)).getNameCategory() %></a></div>
    <%
                }
    %>
</div>
